Repository navigation
fix: share OAuth refreshes across server processes via a lock file - #52
Merged
beautyfree merged 4 commits intoNov 13, 2026
Merged
Conversation
Every MCP client session starts its own server process, and all of them read one credentials.json. Each process read the file once at startup and refreshed with the refresh token it held in memory. Linear rotates the refresh token on every refresh, so once one process refreshed, the others sent a revoked token and failed with "Failed to refresh the stored Linear access token (... HTTP 400)" until the client reconnected. Refreshes now run under a cross-process lock (credentials.json.lock, created with O_EXCL; a lock older than 60s is reclaimed). Under the lock the file is read again: a token another process already refreshed is reused without a request, and an expired one is refreshed with the newest refresh token from the file. If Linear still rejects the refresh and the file now holds a different refresh token (a server build that does not take the lock rotated it meanwhile), that token is adopted or retried exactly once. `auth login` and `auth logout` also write or delete under the lock, and a refresh no longer recreates credentials that were logged out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With stored OAuth credentials (
mcp-linear auth login), Linear tools start failing after a while with:It happens whenever more than one server process uses the same config directory, which is the normal case: every MCP client session (each Claude Code or Codex window, for example) starts its own stdio server. I had 45 server processes running on one machine, all reading the same
credentials.json, and hit the error in five sessions over three days. Reconnecting the MCP server in the failing session made it work again, and logging in again was not needed.Cause
createStoredCredentialAuthreadscredentials.jsononce at startup and keeps the credentials in memory.refresh()sends the in-memory refresh token. Linear rotates the refresh token on every refresh, so the old one stops working as soon as any process refreshes.pendingRefreshonly serializes refreshes inside one process, so it cannot prevent this.Fix
fs-native-extensions. The permanent lock file is not removed or reclaimed by age; the OS releases the lock on process exit. A waiter times out after 75 seconds.npm ci.Verification
npm testpassed (284 tests and MCP smoke test);npm run buildpassed.runAuthCliwith the real loopback OAuth callback and a controlled token response. Removing the production login lock makes this test fail.Notes
npm run lintfails because ESLint 9 finds no flat config; the same configuration issue was reported onmain.